from flask import Flask, session
from flask_sqlalchemy import SQLAlchemy
from redis import StrictRedis
from flask_wtf.csrf import CSRFProtect
from flask_session import Session

class Config(object):
    DEBUG = True
    SQLALCHEMY_DATABASE_URI = "mysql://root:mysql@127.0.0.1:3306/test_17"
    SQLALCHEMY_TRACK_MODIFICATIONS = True

    REDIS_HOST = "127.0.0.1"
    REDIS_PORT = 6379
    REDIS_NUM = 7
    SECRET_KEY = '209khHexoczVNNVWAHuB+OBGNeE5pP/OSSUC8Esc94agk5eu3OktRHtbvvxtQDtg'
    SESSION_TPYE = "redis"
    SESSION_REDIS = StrictRedis(host=REDIS_HOST, port=REDIS_PORT, db=REDIS_NUM)
    SESSION_USE_SIGNER = True
    SESSION_PERMANENT = False
    PERMANENT_SESSION_LIFETIME = 86400 *2#秒为单位

app = Flask(__name__)

app.config.from_object(Config)
db = SQLAlchemy(app)
redis_store = StrictRedis(host=Config.REDIS_HOST,
                          port=Config.REDIS_PORT,
                          db=Config.REDIS_NUM ,
                          decode_responses=True)
# TODO 设置csrf_token值到cookie里面还需要自己去设置
csrf = CSRFProtect(app)
Session(app)

@app.route('/demo')
def demo():
    session["name"] = "curry"
    return "demo"

if __name__ == '__main__':
    app.run(debug=True)
